<?php
/**
 * @author Erling Owe <erling.owe@gmail.com>
 * @package Core
 * @subpackage Presentation
 */

class Core_Presentation_HTML_TextNode {

    private $Document;
    private $strText;
    private $boolConvert = true;

    function __construct ( $objDocument, $strText = "" ) {
        $this->Document = $objDocument;
        $this->strText = $strText;
    }

    function __toString () {
        return ( $this->boolConvert ) ? htmlspecialchars( $this->strText ) : $this->strText;
    }

    public function convertHTMLSpecialChars ( $boolConvert ) {
        $this->boolConvert = $boolConvert;
    }

    public function parent () {
        if ( in_array( $this, $this->Document->children() ) ) {
            return $this->Document;
        } else {
            foreach ( $this->Document->find() as $objNode ) {
                if ( $objNode instanceof Core_Presentation_HTML_TextNode ) {
                    if ( in_array( $this, $objNode->children() ) ) {
                        return $objNode;
                    }
                }
            }
        }
    }

    public function setText ( $strText ) {
        $this->strText = (string) $strText;
    }

}

?>
